%Declare the symbolic variables (syms)
syms PbVal PbLeadVal RVal %rVal PiLeadVal
f= -Pb*exp(PbVal) + (1+rho * Pb*exp(PbLeadVal)) / (R*exp(RVal));

%Take symbolic derivatives
dd1 = diff(f,PbVal);
dd2 = diff(f,PbLeadVal);
dd3=diff(f,RVal);

%Evaluates symbolic derivatives

PbVal=0;  %loglin
PbLeadVal=0;  %loglin
RVal=0;


D1=subs(dd1);
D2=subs(dd2);
D3=subs(dd3);

% Transform symbolic into numbers (with double precision)
d1=double(D1);
d2=double(D2);
d3=double(D3);

ACont(ii,pbLog)        = d1;
ALead(ii,pbLog)       = d2;
ACont(ii,RLog)        =d3;